var mongoose = require("mongoose");
var dbhost = "localhost";
var dbport = 27017;
var dbname = "wuhan2004";
var dbuser = "?";
var dbpass = "?";

var db_conn_str = `mongodb://${dbhost}:${dbport}/${dbname}`;

mongoose.connect(db_conn_str,{
    useNewUrlParse:true,
    useUnifiedTopology:true
},function(err){
    if(err){
        console.log("数据库连接失败...")
        console.log(err)
    }else{
        console.log("数据库连接成功...")
    }
})

const connection = mongoose.connection;

connection.on("connected",()=>{
    console.log("数据库已连接")
})

connection.on("err",()=>{
    console.log("数据库异常")
})

connection.on("disconnected",()=>{
    console.log("数据库断开连接...")
})

module.exports = connection;